package org.wjw;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.MessageFormat;

@WebServlet("/parameter")
public class ParameterServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置请求编码集
        req.setCharacterEncoding("UTF-8");
        // 通过getParameter()来获取具体的参数值
        String studentId = req.getParameter("studentId");
        String studentName = req.getParameter("studentName");
        //构造打印字符串
        String str = MessageFormat.format("GET studentId = {0}, studentName = {1}",studentId,studentName);
        //打印日志
        System.out.println(str);
        //设置返回格式
        resp.setContentType("text/html; charset=utf-8");
        //返回响应
        resp.getWriter().write(str);

    }
}
